#include "pointcloudvisualization.h"
#include "ui_pointcloudvisualization.h"

QQueue<PointCloud_t> d_queue;

PointCloudVisualization::PointCloudVisualization(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PointCloudVisualization) {
    ui->setupUi(this);

}

void PointCloudVisualization::init() {

    scatter = new Q3DScatter();

    ui->widget = QWidget::createWindowContainer(scatter, this);
    ui->widget->setGeometry(0, 0, 700, 600);

    scatter->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFrontLow);
    //scatter->scene()->activeCamera()->setCameraPosition(0, -90);
    scatter->setShadowQuality(QAbstract3DGraph::ShadowQualityNone);//设置 无阴影

    //YZ互换
    scatter->axisX()->setTitle("axis X");
    scatter->axisX()->setTitleVisible(true);
    scatter->axisX()->setRange(-400, 400);
    scatter->axisY()->setTitle("axis Z");
    scatter->axisY()->setTitleVisible(true);
    scatter->axisY()->setRange(0, 350);
    scatter->axisZ()->setTitle("axis Y");
    scatter->axisZ()->setTitleVisible(true);
    scatter->axisZ()->setRange(-400, 400);

    scatter->axisX()->setLabelAutoRotation(30);
    scatter->axisY()->setLabelAutoRotation(30);
    scatter->axisZ()->setLabelAutoRotation(30);

    series->setItemLabelFormat("@xLabel @yLabel @zLabel");
    series->setMeshSmooth(true);
    series->setMesh(QAbstract3DSeries::MeshSphere);//数据点为圆球
    series->setSingleHighlightColor(QColor(0, 0, 255)); //设置点选中时的高亮颜色
    series->setBaseColor(QColor(0, 255, 255)); //设置点的颜色
    series->setItemSize(0.03);//设置点的大小
}

void PointCloudVisualization::drawPoints() {
    //点坐标要YZ互换
    static QScatterDataArray drawDataArray;
    int len = d_queue.count();

    for(int i = 0; i < len; i++) {
        drawDataArray.append(d_queue.dequeue().point);
    }

    series->dataProxy()->resetArray(&drawDataArray);
    scatter->addSeries(series);
}

PointCloudVisualization::~PointCloudVisualization() {
    delete scatter;
    delete series;
    delete ui;
}
